#ifndef HUZHOU_ROS_H
#define HUZHOU_ROS_H

#include "ros/ros.h"
#include "std_msgs/String.h"
#include "std_msgs/Bool.h"

#include <functional>
#include <string>

namespace hzros{

    inline ros::Publisher req_pub;
    inline ros::Publisher req_ui_pub;
    

    inline ros::Subscriber sub;
    inline ros::Subscriber stop_sub;

    inline ros::Subscriber tts_sub;
    inline ros::Subscriber ctrl_sub;


    inline void init(int argc, char ** argv,
        std::function<void(const std_msgs::String::ConstPtr&)> llm_res_sub_callback,
        std::function<void(const std_msgs::String::ConstPtr&)> stop_sig_sub_callback,
        std::function<void(const std_msgs::String::ConstPtr&)> tts_sig_sub_callback,
        std::function<void(const std_msgs::Bool::ConstPtr&)> ctrl_sig_sub_callback) {

        // 初始化 ros 节点和订阅者信息
        ros::init(argc, argv, "know_asr_llm_node");
        ros::NodeHandle nh;

        sub = nh.subscribe<std_msgs::String>( "huzhou_llm_res", 10, llm_res_sub_callback);
        stop_sub = nh.subscribe<std_msgs::String>("huzhou_llm_stop", 10, stop_sig_sub_callback);

        req_pub = nh.advertise<std_msgs::String>("huzhou_llm_req", 10);
        req_ui_pub = nh.advertise<std_msgs::String>("huzhou_llm_req_ui", 10);

        // 语音合成的 sub
        tts_sub = nh.subscribe<std_msgs::String>("know_tts", 10, tts_sig_sub_callback);

        // 暂停和继续服务的 sub
        ctrl_sub = nh.subscribe<std_msgs::Bool>("know_ctrl", 10, ctrl_sig_sub_callback);

    }

    inline void pubQuestion(std::string &question) {
        std_msgs::String msg;
        msg.data = question;
        req_pub.publish(msg);
    }

    inline void pubQuestionToUi(std::string &question) {
        std_msgs::String msg;
        msg.data = question;
        req_ui_pub.publish(msg);

        // 向ui节点发送结束符
        msg.data = "[DONE]";
        req_ui_pub.publish(msg);
    }

    inline void spin(void) {
        ros::spin();
    }
};

#endif // HUZHOU_ROS_H
